/*初始化datagrid*/
$(function () {
    /*抽取常用组件*/
    var log_list = $("#log_list");
    var log_dialog = $("#log_dialog");
    /*对象管理方法*/
    var object = {
        cancel: function () {
            log_dialog.dialog('close');
        }
        ,
        reload: function () {
            log_list.datagrid('reload');
        }
        ,
        query: function () {
            var minTime = $("#minTime").datebox('getValue');
            var maxTime = $("#maxTime").datebox('getValue');

            log_list.datagrid('load', {
                minTime: minTime,
                maxTime: maxTime
            });
        },
        exportEmp: function () {
            var minTime = $("#minTime").datebox('getValue');
            var maxTime = $("#maxTime").datebox('getValue');
            window.location.href = '/log/export.do?minTime=' + minTime + '&maxTime=' + maxTime;
        },
        deleteAll: function () {
            var minTime = $("#minTime").datebox('getValue');
            var maxTime = $("#maxTime").datebox('getValue');
            var tip;
            if (minTime == '' && maxTime == '') {
                tip = '本操作将删除全部日志,请注意备份,是否确认删除?';
            } else {
                tip = '将删除该时段内的所有日志,是否确认删除?';
            }
            $.messager.confirm('温馨提示',tip, function (r) {
                if (r) {
                    $.get('/log/deleteAll.do', {minTime: minTime, maxTime: maxTime}, function (data) {
                        if (data.success) {
                            $.messager.alert('温馨提示', data.msg, 'info', function () {
                                log_list.datagrid('reload');
                            });
                        } else {
                            $.messager.alert('温馨提示', data.msg, 'error');
                        }
                    })
                }
            })
        }
    }
    /*事件统一绑定*/
    $("[data-cmd]").click(function () {
        var cmd = $(this).data('cmd');
        object[cmd]();
    })

    log_list.datagrid({
        fit: true,
        rownumbers: true,
        fitColumns: true,
        pagination: true,
        singleSelect: true,
        pageSize: 15,
        pageList: [10, 15, 20, 30],
        toolbar: '#log_toolbar',
        url: '/log/query.do',
        onDblClickRow:function (index, row) {
            $("#log_form").form('load',{
                opuser:row.opuser.realname,
                optime:row.optime,
                IP:row.opip,
                function:row.function,
                params:row.params,
            });
            log_dialog.dialog('open');
        },
        columns: [[
            {
                field: 'opuser', title: '操作人', width: 100, formatter: function (value, row, index) {
                    return value.realname;
                }
            },
            {field: 'optime', title: '操作时间', width: 200},
            {field: 'opip', title: 'IP地址', width: 150},
            {field: 'function', title: '操作详情', width: 300},
            {field: 'params', title: '参数', width: 300},

        ]]
    })

    log_dialog.dialog({
        title:'日志详情',
        closed: true,
        width: 350,
        height: 380,
        buttons: $("#log_diaButtons"),
    })

})
